package org.wheel.module.core.enm;

import org.wheel.module.core.exception.CustomAssert;
import org.wheel.module.core.exception.ServiceExceptionEnum;

/**
 * 异常枚举
 *
 * @author lanjf2000
 * @Date 2020/09/15
 */
public enum NormalExceptionEnum implements ServiceExceptionEnum, CustomAssert {

	// 通用反馈信息 操作成功
	OPERATE_SUCCESS(200, "操作成功", ""),
	// 通用反馈信息 警告操作
	OPERATE_WARNING(400,"警告操作",""),
	// 通用反馈信息 操作失败
	OPERATE_FAIL(500, "操作失败", ""),
	// 通用反馈信息 操作过于频繁
	OPERATION_FREQUENT(4004, "访问过于频繁，请稍后再次请求", ""),

	/**
	 * 40[00-19]权限和数据问题
	 */
	DB_RESOURCE_NULL(4001,"数据库中没有该资源", ""),
	NO_PERMITION(4002, "权限异常", ""),
	REQUEST_INVALIDATE(4003,"请求数据格式不正确", ""),
//	PERMITION＿EXPIRED(4005, "权限过期", ""),
	PERMITION＿EXPIRED(4005, "登录超时，请重新登录", ""),
	INVALID_KAPTCHA(4006,"验证码不正确", ""),
	INVALID_KAPTCHA_NOT_FOUND(4007,"验证码未找到", ""),
	INVALID_KAPTCHA_EXPIRED(4008,"验证码过期", ""),
	INVALID_KAPTCHA_RENDERING_FAIL(4009,"验证码渲染失败", ""),
	
	CANT_DELETE_ADMIN(4010,"不能删除超级管理员", ""),
	CANT_FREEZE_ADMIN(4011,"不能冻结超级管理员", ""),
	CANT_CHANGE_ADMIN(4012,"不能修改超级管理员角色", ""),

	/**
	 * 40[20-39]账户问题
	 */
	USER_ALREADY_REG(4020,"该用户已经注册", ""),
	
	USER_PWD_ERROR(4021,"用户名或密码不正确", ""),
	USER_PHONE_ERROR(4022,"手机号不存在", ""),
	USER_NO_LOGIN(4023,"用户未登陆", ""),
	USER_NOT_EXISTED(4024, "用户不存在","smartbiding.sysSetting.noExit"),
	ACCOUNT_FREEZED(4025, "账号被冻结", ""),
	OLD_PWD_NOT_RIGHT(4026, "原密码不正确", ""),
	@Deprecated
	TWO_PWD_NOT_MATCH(4027, "两次输入密码不一致", ""),
	VALIDATE_CHAR_NOT_MATCH(4028, "验证码不正确", ""),
	VALIDATE_CHAR_EXPIRED(4029, "验证码过期", ""),
	VALIDATE_CHAR_EMPTY(4030, "验证码为空", ""),
	VALIDATE_CHAR_SUCCESS(4031, "验证码验证通过", ""),
	VALIDATE_CHAR_FAIL(4032, "验证码验证失败", ""),
	USER_NO_WXOPENID(4033,"该微信账户未绑定系统账号!",""),
	WXOPENID_ALREADY_REG(4035,"该微信账户已经存在绑定账号!",""),
	ACCOUNT_ALREADY_BIND(4036,"该账户已经存在绑定的微信账号!",""),
	ACCOUNT_EXPIRED(4037, "登录用户账号过期，请联系管理员", ""),
	ACCOUNT_DISABLED(4038, "用户已被禁用，不允许登录系统", ""),
	/**
	 * 40[40-69]错误的请求
	 */
	MENU_PCODE_COINCIDENCE(4040,"菜单编号和副编号不能一致", ""),
	EXISTED_THE_MENU(4041,"菜单编号重复，不能添加", ""),
	DICT_MUST_BE_NUMBER(4042,"字典的值必须为数字", ""),
	REQUEST_NULL(4043, "请求有错误", ""),
	@Deprecated
	SESSION_TIMEOUT(4044, "会话超时", ""),
	SERVER_ERROR(4045, "服务器异常", ""),

    /**
     * 40[70-99]字典
     */
    DICT_EXISTED(4070, "字典已经存在", ""),
    ERROR_CREATE_DICT(4071,"创建字典失败", ""),
    @Deprecated
    ERROR_WRAPPER_FIELD(4072,"包装字典属性失败", ""),

    /**
     * 41[00-19]文件上传
     */
    FILE_READING_ERROR(4100,"文件读取错误", "nomalexceptionenum.file-reading-error"),
    FILE_NOT_FOUND(4101, "文件未找到", "nomalexceptionenum.file-not-found"),
    UPLOAD_ERROR(4102, "文件上传错误", "nomalexceptionenum.upload-error"),
    
    /**
     * 50[00-19]其他
     */
    WRITE_ERROR(5000, "写入错误", "nomalexceptionenum.write-error"),
    
    /**
     * 对象非空判断
     */
	OSS_IS_NULL(30140, "配置服务出错", "C0140"),
	EMPTY(0000, "空对象", ""); // 用于空对象的调用, 比如断言的时候, 需要自定义信息的时候, 可以用此对象

	NormalExceptionEnum(int code, String message, String i18nMessage) {
		this.code = code;
		this.message = message;
		this.i18nMessage = i18nMessage;
	}

	private Integer code;

	private String message;
	
	private String i18nMessage;

	@Override
	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getI18nMessage() {
		return i18nMessage;
	}

	public void setI18nMessage(String i18nMessage) {
		this.i18nMessage = i18nMessage;
	}

	public void setMessage(String message) {
		this.message = message;
	}
	
    public String getMessage() {
        return message;
//		return messageSource.getMessage(message, null, message, LocaleContextHolder.getLocale());
//    	return LocaleStringUtil.getMessage(message);
    }

    @Override
    public void assertNotNull(Object o) {
        CustomAssert.super.assertNotNull(o, this);
    }
}
